<template>
  <div class="table-page-search-wrapper">
    <a-card>
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :md="6" :sm="12">
            <a-form-item
                label="学号"

            >
              <a-input v-model="queryParam.xh"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item
              label="姓名"

            >
              <a-input v-model="queryParam.xm"/>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
            <a-col :md="6" :sm="12">
              <a-form-item
                label="学生来源"
              >
                <a-select :allowClear="true" v-model="queryParam.xslxm">
                  <a-select-option v-for="i in TYPE0503" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item
                label="学生类别"

              >
                <a-select v-model="queryParam.xslbm">
                  <a-select-option v-for="i in TYPE0075" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

            <a-col :md="6" :sm="12">
              <a-form-item label="培养单位">
                <a-select allowClear v-model="queryParam.pydw" @change="yxChange" showSearch :filterOption="filterOption">
                  <a-select-option v-for="i in selectMenu.yxList" :key="i.id" :value="i.dwh">{{ i.dwh }} {{ i.dwmc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="专业">
                <a-select allowClear v-model="queryParam.zyh" showSearch :filterOption="filterOption">
                  <a-select-option v-for="i in selectMenu.zyList" :key="i.id" :value="i.zyh">{{ i.zyh}} {{ i.zymc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="年级">
                <a-select allowClear v-model="queryParam.sznj">
                  <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="考核状态">
                <a-select allowClear v-model="queryParam.khzt">
                  <a-select-option v-for="i in TYPE0339" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item label="是否通过">
                <a-select allowClear v-model="queryParam.sftg">
                  <a-select-option v-for="i in TYPE0117" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="24" :sm="24">
            <span class="table-page-search-submitButtons" >
              <a-button type="primary" @click="$refs.table.refresh(true)" style="margin:0 8px">查询</a-button>
              <!-- <a-button type="primary" @click="exportExcel">导出EXCEL</a-button>
              <a-button type="primary" style="margin-left: 8px;" @click="exportPDF">导出WORD</a-button> -->
             <a-button type="primary" @click="exportExcel">导出</a-button>
              <a-button @click="queryParam = {};$refs.table.refresh()" style="margin-left: 8px;">重置</a-button>
              <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <div style="margin-top: 10px; background-color: white">
      <s-table
        v-if="init"
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        :alert="{show: true}"
        :scroll="{ x: 1200 }"
        :pageSize="parameter.pageSize"
        :pageNum="parameter.pageNum"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 + (parameter.pageNo - 1) * parameter.pageSize }}
        </span>
        <template slot="operation" slot-scope="id, record">
          <a-popconfirm v-hasPermission="'ktbkgl:back'" v-if="record.sftgzqkh == '1'" title="是否要退回此中期考核？" @confirm="back(id)">
            <a>退回</a>
          </a-popconfirm>
        </template>
      </s-table>
    </div>

    <!-- <check-modal
      ref="check"
      :visible="visible"
      @cancel="visible = false"
      @refresh="$refs.table.refresh(false)"
    />

    <detailModal
      ref="detail"
      :visible="detailVisible"
      @cancel="detailVisible = false"
    /> -->
  </div>
</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'
import searchMixin from '@/utils/searchRemain'

export default {
  mixins: [ searchMixin ],
  data () {
    return {
      advanced: true,
      queryParam: {},
      columns: [
        {
          title: '序号',
          width:69,
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '学号',
          dataIndex: 'xh',
          width:120,
        },
        {
          title: '姓名',
          width: 80,
          dataIndex: 'xm'
        },
        {
          title: '所属院系',
          dataIndex: 'ssyxmc'
        },
        {
          title: '专业',
          dataIndex: 'sszymc'
        },
        {
          title: '学生类别',
          width: 80,
          dataIndex: 'xslbmc'
        },
        {
          title: '导师姓名',
          dataIndex: 'dsxm'
        },
        {
          title: '状态',
          width: 80,
          dataIndex: 'zqkhztmc'
        },
        {
          title: '考核是否通过',
          dataIndex: 'sftgzqkhmc',
          width: 100
        },
        {
          title: '退回次数',
          width: 100,
          dataIndex: 'backTimes'
        },
        {
          title: '创建时间',
          dataIndex: 'createDate',
          width: 110
        },
        {
          title: '操作',
          dataIndex: 'id',
          width: 120,
          scopedSlots: { customRender: 'operation' },
          fixed: 'right'
        }
      ],
      parameter: {
        pageNo: 1,
        pageSize: 10
      },
      loadData: parameter => {
        this.parameter = parameter
        parameter.pageNum = parameter.pageNo
        let params = Object.assign(this.queryParam, parameter)
        return this.$api.cultivate.midTermList(params).then(res => {
          return {
            data: res.data.rows,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      selectMenu: {},
      visible: false,
      detailVisible: false,
      init: false,
      uploading: false,
      fileList: [],
    }
  },
  components: {STable, },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0075: state => state.app['TYPE0075'],
      TYPE0126: state => state.app['TYPE0126'],
      TYPE0503: state => state.app['TYPE0503'],
      TYPE0337: state => state.app['TYPE0337'],
      TYPE0339: state => state.app['TYPE0339'],
      TYPE0117: state => state.app['TYPE0117'],
    }),
    routeName () {
      return this.$route.name
    }
  },
  created () {
    this.$store.dispatch('app/setDictionary', 'TYPE0075')
    this.$store.dispatch('app/setDictionary', 'TYPE0503')
    this.$store.dispatch('app/setDictionary', 'TYPE0126')
    this.$store.dispatch('app/setDictionary', 'TYPE0337')
    this.$store.dispatch('app/setDictionary', 'TYPE0339')
    this.$store.dispatch('app/setDictionary', 'TYPE0117')
    // this.initSelectMenu()
    // if (this.$route.name === '开题报告审核') {
    //   // this.columns.splice(11, 0, {
    //   //   title: '是否开题',
    //   //   dataIndex: 'sfktmc'
    //   // })
    //   this.columns.push({
    //     title: '操作',
    //     dataIndex: 'id',
    //     scopedSlots: { customRender: 'operation' },
    //     fixed: 'right'
    //   })
    // }
  },
  watch: {
    'routeName' (name) {
      // if (name === '开题报告审核') {
      //   // this.columns.splice(11, 0, {
      //   //   title: '是否开题',
      //   //   dataIndex: 'sfktmc'
      //   // })
      //   this.columns.push({
      //     title: '操作',
      //     dataIndex: 'id',
      //     scopedSlots: { customRender: 'operation' },
      //     fixed: 'right'
      //   })
      // } else {
      //   this.columns.splice(12, 1)
      // }
      this.queryParam = {}
      this.$set(this.queryParam, 'sznj', this.systemInfo.currentGrade)
      this.$refs.table.refresh(true)
    }
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll(),
        this.$store.dispatch('app/sysInfo')
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yxList: res[0].data
        }
        this.$set(this.queryParam, 'sznj', res[1].currentGrade)
        //this.$set(this.queryParam, 'sznj', res[1].currentGrade)
        this.init = true
      })
    },
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    yxChange (code) {
      this.$set(this.queryParam, 'zyh', '')
      if (code) {
        this.$api.base.majorAll({lsdwh: code}).then(res => {
          this.$set(this.selectMenu, 'zyList', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'zyList', [])
      }
    },
    showCheck (id) {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.check.form.resetFields()
        this.$refs.check.tableData = []
      })
      this.$api.cultivate.openingDetail(id).then(res => {
        this.$refs.check.rptInfo = res.data
      })
    },
    back (id) {
      this.$api.cultivate.midBack(id).then(res => {
        this.$message.success(res.data)
        this.$refs.table.refresh(false)
      })
    },
    exportExcel () {
      let params = {...this.queryParam}
      delete params.pageNum
      this.$export('/foster/zqkhxx/listExp', params)
    }
  }
}
</script>

<style>

</style>
